set more off

*** read data ***

set more off

use "reassessments", clear

merge 1:1 swis_code year using "switchers"
keep if _m == 3
drop _m

merge m:m muni_name county_name year using "census demographics"
drop _m

merge m:m muni_name county_name year using "finances clean"
drop _m

merge m:m muni_name county_name year using "employment"
drop _m

merge m:m swis_code year using "salesweb"
keep if _m == 3
drop _m

*** recode for interpretation ***

gen elected = 1-D
su lprice
replace lprice = (lprice - r(min)) / (r(max) - r(min))
replace rar = rar * 100

*** controls ***

#delimit;

local X 
	lpopulation 
	lmedianincome 
	pct65plus 
	pctwhite 
	pctunemployed 
	pctrenter 
	pctagricuture
	ltotalrevenue
	pctptax
	surpluspcp
	totalftequivalent
	;

#delimit cr

*** do the regressions ***

gen electedXlprice = elected*lprice 

eststo clear

eststo: xi: areg rar elected i.year, a(swis_code) cl(swis_code)
eststo: xi: areg rar elected i.year `X', a(swis_code) cl(swis_code)

eststo: xi: areg rar lprice elected electedXlprice i.year, a(swis_code) cl(swis_code)
su rar if e(sample)
local mymean = string(r(mean), "%20.02fc")
eststo: xi: areg rar elected lprice electedXlprice i.year `X', a(swis_code) cl(swis_code)

label variable lprice "Sale price (log)"
label variable elected "Elected assessor"
label variable electedXlprice "Elected $\times$ price"

#delimit;

esttab
	using "table 2.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		gap
		keep(elected electedXlprice lprice)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		indicate("Controls = lpopulation")
		stats(

			N
			,
				label(

					"Observations"
						
				)
				fmt(%20.0fc)
		)
		
		;
	
#delimit cr

shell "tabler.sh" "table 2.tex" "Effective tax rate" "Property"
